package com.itheima.网络编程.tcp编程.tcp编程.tcp网络编程;

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

public class TcpDemo3 {
    public static void main(String[] args) throws IOException {
        Socket sk = new Socket("127.0.0.1", 10000);
        Scanner sc = new Scanner(System.in);
        OutputStream out = sk.getOutputStream();
        OutputStreamWriter osw = new OutputStreamWriter(out);
        BufferedWriter bw = new BufferedWriter(osw);
        System.out.println("请输入数据:");
        String message = sc.next();
        bw.write(message);
        sk.shutdownOutput();
        System.out.println("========================");
        BufferedReader br=new BufferedReader(new InputStreamReader(sk.getInputStream()));
        System.out.println(br.readLine());
        out.close();
        sk.close();
    }

    public static void demo45() throws IOException {
        Socket sk = new Socket("127.0.0.1", 10000);
        Scanner sc = new Scanner(System.in);
        OutputStream out = sk.getOutputStream();
        OutputStreamWriter osw = new OutputStreamWriter(out);
        BufferedWriter bw = new BufferedWriter(osw);
        while (true) {
            System.out.println("请输入数据:");
            String message = sc.next();
            if ("886".equals(message)) {
                break;
            } else {
                bw.write(message);
            }
        }
        out.close();
        sk.close();
    }
}
